package partie4.router;

import jpcap.NetworkInterface;
import jpcap.PacketReceiver;
import jpcap.packet.ARPPacket;
import jpcap.packet.IPPacket;
import jpcap.packet.Packet;

public class Receiver implements PacketReceiver{
	NetworkInterface device;
	
	public Receiver(NetworkInterface device){
		this.device = device;
	}
	
	/**
	 * Fonction appelee lorsque l'on recoit un paquet.
	 * @param arg0 Le paquet recu.
	 */
	@Override
	public void receivePacket(Packet arg0) {
		//Paquet IP
		if(arg0 instanceof IPPacket) { 
			  IPPacket ipPacket = (IPPacket) arg0; 
			  
			  //envoyer le paquet recu
			  Router.getInstance().sendPacket(ipPacket, this.device);
		}
		//Paquet ARP
		else if (arg0 instanceof ARPPacket){
			ARPPacket arpPacket = (ARPPacket) arg0;
			
			//envoyer le paquet recu
			Router.getInstance().sendPacket(arpPacket, this.device);
		}
	}
	

}
